package com.software.modelcenter.service;

import cn.hutool.log.Log;
import com.software.modelcenter.entity.ModelType;
import com.software.modelcenter.repository.ModelTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Author xiaoliao
 * @Date 2023/4/26 14:32
 */
@Service
public class ModelTypeService {
    @Autowired
    private ModelTypeRepository modelTypeRepository;

    public ModelType findById(String id) {
        Optional<ModelType> optional = modelTypeRepository.findById(id);
        ModelType modelType = null;
        if (optional.isPresent()) {
            modelType = optional.get();
            return modelType;
        }
        else {
            System.out.println("typeId 不存在");
            return modelType;
        }


    }

    public List<ModelType> findAll() {
        return modelTypeRepository.findAll();
    }

    public Page<ModelType> findAll(Integer pageNo, Integer pageSize) {
        Pageable pageable = PageRequest.of(pageNo, pageSize);
        return modelTypeRepository.findAll(pageable);
    }

    public ModelType insertModelType(ModelType modelType) {
        return modelTypeRepository.save(modelType);
    }

    public void deleteModelTypeByTypeId(String typeId) {
        ModelType modelType = findById(typeId);
        modelTypeRepository.delete(modelType);
    }

    public void updateModelType(ModelType modelType) {
        modelTypeRepository.save(modelType);
    }

//    public List<ModelType> findByTypeDescriptionLike(String typeDescription) {
//        return modelTypeRepository.findByTypeDescriptionLike(typeDescription);
//    }
//
//    public List<ModelType> findByTypeDescriptionLikeOrTypeNameLike(String s) {
//        return modelTypeRepository.findByTypeDescriptionLikeOrTypeNameLike(s,s);
//    }
}
